﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;

namespace nextGeneration_app
{
    public partial class teacher_editPersonalInfo : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string userID = Session["loginID"].ToString();
            string userPassword = Session["loginPassword"].ToString();

            teacher_basicInfo info = teacher_dbManager.getUserBasicInfo(userID);
            lblFullName.Text = info.UserName;
            lblEmailAddress.Text = info.UserEmail;
            lblRegisteredDate.Text = Convert.ToString(info.UserRegisterDate);

            teacherUser teacher = teacher_dbManager.retrieve_teacherInfo(userID);
            lblStaffID.Text = teacher.ID;
            tbxPassport.Text = teacher.Passport;
            tbxFinNumber.Text = teacher.Fin;
            lblGender.Text = teacher.Gender;
            lblDateOfBirth.Text = Convert.ToString(teacher.DOB);
            tbxRace.Text = teacher.Race;
            tbxCitizenShip.Text = teacher.Citizen;
            ddlReligion.SelectedItem.Text = teacher.Religion;
            ddlCountryOfBirth.SelectedItem.Text = teacher.BirthCountry;
            ddlMaritalStatus.SelectedValue = teacher.MaritalStatus;

            teacherAddress address = teacher_dbManager.getTeacherAddress(userID);
            tbxBlockNumber.Text=address.HomeBlkNumber;
            tbxUnitNumber.Text=address.HomeUnitNumber;
            tbxStreetName1.Text=address.StreetName;
            tbxState.Text = address.StateName;
            DropDownList1.SelectedItem.Text = address.Country;
            tbxPostalCode.Text=Convert.ToString(address.PostalCode);
            tbxTelephoneNumber.Text=Convert.ToString(address.TelephoneNumber);
            tbxHandPhoneNumber.Text = Convert.ToString(address.HandPhoneNumber);
          
        }

       protected void btnClear_Click(object sender, EventArgs e)
        {
            tbxBlockNumber.Text = null;
            tbxCitizenShip.Text = null;
            tbxFinNumber.Text = null;
            tbxHandPhoneNumber.Text = null;
            tbxPassport.Text = null;
            tbxPostalCode.Text = null;
            tbxState.Text = null;
            tbxStreetName1.Text = null;
            tbxTelephoneNumber.Text = null;
            tbxUnitNumber.Text = null;
            
        }

       protected void btnSubmit_Click(object sender, EventArgs e)
       {
           string userID = Session["loginID"].ToString();
           string userPassword = Session["loginPassword"].ToString();

           FileInfo info = new FileInfo(FileUploadImage1.Value.Trim());
           byte[] content = new byte[info.Length];
           FileStream imagestream = info.OpenRead();
           imagestream.Read(content, 0, content.Length);
           imagestream.Close();

           string passport = tbxPassport.Text;
           string finNumber = tbxFinNumber.Text;
           string race = tbxRace.Text;
           string religion = ddlReligion.SelectedItem.Text;
           string maritalStatus = ddlMaritalStatus.SelectedItem.Text;
           string citizen = tbxCitizenShip.Text;
           string birthCountry = ddlCountryOfBirth.SelectedItem.Text;

           teacherUser teacher = new teacherUser(userID, content, passport, finNumber, race, religion, maritalStatus, citizen, birthCountry);

           bool result = teacher_dbManager.updateTeacherInfo(userID, teacher);
           if (result == true)
           {
              
           }


       }
    }
}